package sample;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class FileStatus {

    public static File f = new File("untitled");

    //获取文本文件中的全部内容，以utf-8编码返回字符串
    public static String getContent(File file) throws IOException {
        FileInputStream in = new FileInputStream(file);
        byte[] fileContent = new byte[(int)file.length()];
        in.read(fileContent);
        in.close();
        return new String(fileContent, StandardCharsets.UTF_8);
    }

    //写入文本
    public static void setContent(File file, String s) throws IOException {
        FileWriter fw = new FileWriter(file);
        fw.write(s);
        fw.close();
    }

}
